<template>
  <div class="list">
    <img :src="currentCategory.wap_banner_url" alt="" />
    <div class="title">
      {{ currentCategory.name + "分类" }}
    </div>
    <ul class="goods">
      <li
        v-for="item in currentCategory.subCategoryList"
        class="item"
        @click="itemClick(item.id)"
      >
        <img :src="item.wap_banner_url" alt="" @load="imageLoad" />
        <p class="name">{{ item.name }}</p>
      </li>
    </ul>
  </div>
</template>
<script>
// import Cate from "components/common/Cate.vue";

import { getCatalogCurrent } from "network/category";
export default {
  name: "List",
  data() {
    return {
      currentCategory: {},
    };
  },
  // component: {
  //   Cate
  // },
  created() {
    this.getCatalogCurrent();
  },
  watch: {
    $route(to, from) {
      //监听路由是否变化
      this.getCatalogCurrent();
    },
  },
  methods: {
    getCatalogCurrent() {
      getCatalogCurrent(this.$route.params.id)
        .then((res) => {
          this.currentCategory = res.data.data.currentCategory;
          // this.goodsList = this.currentCategory.subCategoryList
        })
        .catch((err) => {
          console.log(err);
        });
    },
    itemClick(subCategoryId) {
      this.$router.push(
        "/goodslist/" + this.currentCategory.id + "/" + subCategoryId
      );
    },
    imageLoad() {
      this.$bus.$emit('itemImageLoad')
    },
  },
};
</script>
<style scoped>
.list {
  width: 294px;
  padding: 20px 15px 0;
}
.list img {
  width: 100%;
  height: 96px;
}
.title {
  margin: 15px 0;
  padding-bottom: 4px;
  font-size: 14px;
  color: #333;
  font-weight: 700;
  border-bottom: 1px solid #d9d9d9;
}
.goods {
  overflow: hidden;
}
.goods .item {
  float: left;
  width: 72px;
  height: 108px;
  padding: 0 5px 10px 5px;
  margin-right: 24px;
}
.goods .item:nth-child(3n + 3) {
  margin-right: 0;
}
.goods .item img {
  display: block;
  width: 72px;
  height: 72px;
}
.goods .item .name {
  height: 36px;
  font-size: 12px;
  color: #333;
  text-align: center;
  line-height: 18px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}
.clearfix::before,
.clearfix::after {
  content:'';
  display: table;
}
.clearfix::after {
  clear: both;
}
.clearfix {
  *zoom: 1;
}
</style>